<?php

class HiddenTextForm extends PostBackControl {

	var $ConfigurationManager;

	function HiddenTextForm(&$Context) {
		$this->Name = 'HiddenTextForm';
		$this->ValidActions = array('HiddenText', 'ProcessHiddenText');
		$this->Constructor($Context);
		if (!$this->Context->Session->User->Permission('PERMISSION_HIDDEN_TEXT')) {
			$this->IsPostBack = 0;
		} elseif ($this->IsPostBack) {
			$SettingsFile = $this->Context->Configuration['APPLICATION_PATH'] . 'conf/settings.php';
			$this->ConfigurationManager = $this->Context->ObjectFactory->NewContextObject($this->Context,
				'ConfigurationManager');
			if ($this->PostBackAction == 'ProcessHiddenText') {
				$this->ConfigurationManager->GetSettingsFromForm($SettingsFile);
				// Checkboxes aren't posted back if unchecked, so make sure that they are saved properly
				$this->DelegateParameters['ConfigurationManager'] = &$this->ConfigurationManager;
				$this->CallDelegate('DefineCheckboxes');

				// And save everything
				if ($this->ConfigurationManager->SaveSettingsToFile($SettingsFile)) {
					header(
						'location: ' . GetUrl($this->Context->Configuration, 'settings.php', '', '', '', '',
							'PostBackAction=HiddenText&Success=1'));
				} else {
					$this->PostBackAction = 'HiddenText';
				}
			}
		}
		$this->CallDelegate('Constructor');
	}

	// The crap for the changing the settings
	function Render() {
		if ($this->IsPostBack) {
			$this->CallDelegate('PreRender');

			$this->PostBackParams->Clear();
			if ($this->PostBackAction == "HiddenText") {
				$this->PostBackParams->Set('PostBackAction', 'ProcessHiddenText');
				echo '
						<div id="Form" class="Account HiddenTextSettings">';
				if (ForceIncomingInt('Success', 0)) echo '<div id="Success">' . $this->Context->GetDefinition(
					'ChangesSaved') . '</div>';
				echo '
						<fieldset>
							<legend>' . $this->Context->GetDefinition("HiddenTextSettingsTitle") . '</legend>
							' . $this->Get_Warnings() . '
							' . $this->Get_PostBackForm('frmHiddenText') . '
							<h2>' . $this->Context->GetDefinition("HiddenTextMarkerShow") . '</h2>
							<p>' . $this->Context->GetDefinition("HiddenTextSettingsInfoShow") . '</p>
							<ul>
								<li>
									<label for="txtHiddenTextMarkerShow">' . $this->Context->GetDefinition(
					"SettingsInputTextShow") . '</label>
									<input type="text" name="HIDDEN_TEXT_MARKER_SHOW" id="txtHiddenTextMarkerShow"  value="' . $this->ConfigurationManager->GetSetting(
					'HIDDEN_TEXT_MARKER_SHOW') . '" maxlength="20" class="SmallInput" style="width: 50%;" />
								</li>
							</ul>
							<h2>' . $this->Context->GetDefinition("HiddenTextMarkerHide") . '</h2>
							<p>' . $this->Context->GetDefinition("HiddenTextSettingsInfoHide") . '</p>
							<ul>
								<li>
									<label for="txtHiddenTextMarkerHide">' . $this->Context->GetDefinition(
					"SettingsInputTextHide") . '</label>
									<input type="text" name="HIDDEN_TEXT_MARKER_HIDE" id="txtHiddenTextMarkerHide"  value="' . $this->ConfigurationManager->GetSetting(
					'HIDDEN_TEXT_MARKER_HIDE') . '" maxlength="20" class="SmallInput" style="width: 50%;" />
								</li>
							</ul>
							';
				$this->CallDelegate('PreButtonsRender');
				echo '
							<div class="Submit">
								<input type="submit" name="btnSave" value="' . $this->Context->GetDefinition('Save') . '" class="Button SubmitButton" />
								<a href="' . GetUrl($this->Context->Configuration, $this->Context->SelfUrl) . '" class="CancelButton">' . $this->Context->GetDefinition(
					'Cancel') . '</a>
							</div>
						';
				$this->CallDelegate('PostButtonsRender');
				echo '
							</form>
						</fieldset>
						</div>';

				$this->PostBackParams->Clear();
			}
		}
		$this->CallDelegate('PostRender');
	}
}